package com.elitesland.metadata.entity;

import com.elitesland.core.base.BaseModel;
import com.elitesland.system.annotation.Comment;
import com.elitesland.system.convert.BooleanToIntegerConverter;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Objects;

/**
 * @author mir
 * @date 2020-11-21 02:25:08
 */
@Entity
@Table(name = "meta_field")
@org.hibernate.annotations.Table(appliesTo = "meta_field", comment = "元数据字段定义")
@Data
@Accessors(chain = true)
@ApiModel(value = "元数据字段定义", description = "元数据字段定义")
public class MetaFieldDO extends BaseModel implements Serializable {

    private static final long serialVersionUID = -2424945158137970754L;

    @ApiModelProperty(value = "字段编码")
    @Comment("字段编码")
    @Column(nullable = false, unique = true)
    String fieldCode;

    @ApiModelProperty(value = "字段描述")
    @Comment("字段描述")
    @Column()
    String fieldDesc;

    @ApiModelProperty(value = "字段类型, [UDC]META:FLDTYPE")
    @Comment("字段类型, [UDC]META:FLDTYPE")
    @Column()
    String fieldType;

    @ApiModelProperty(value = "字段长度")
    @Comment("字段长度")
    @Column()
    Integer fieldLength;

    @ApiModelProperty(value = "字段精度")
    @Comment("字段精度")
    @Column()
    Integer fieldPrecision;

    @ApiModelProperty(value = "UDC的Domain Code")
    @Comment("UDC的Domain Code")
    @Column()
    String udcDomainCode;

    @ApiModelProperty(value = "UDC的UDC Code")
    @Comment("UDC的UDC Code")
    @Column()
    String udcCode;

    @ApiModelProperty(value = "UDC默认描述")
    @Comment("UDC默认描述")
    @Column()
    String udcDefaultDesc;

    @ApiModelProperty(value = "页面元素类型")
    @Comment("页面元素类型")
    @Column()
    String pageElement;

    @ApiModelProperty(value = "页面标签")
    @Comment("页面标签")
    @Column()
    String pageLabel;

    @ApiModelProperty(value = "移动端页面元素类型")
    @Comment("移动端页面元素类型")
    @Column()
    String mobileElement;

    @ApiModelProperty(value = "移动端页面标签")
    @Comment("移动端页面标签")
    @Column()
    String mobileLabel;

    @ApiModelProperty(value = "是否必填")
    @Comment("是否必填")
    @Column()
    @Convert(converter = BooleanToIntegerConverter.class)
    Boolean isRequired;

    @ApiModelProperty(value = "最小长度")
    @Comment("最小长度")
    @Column()
    Integer minLength;

    @ApiModelProperty(value = "最大长度")
    @Comment("最大长度")
    @Column()
    Integer maxLength;


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof MetaFieldDO)) {
            return false;
        }
        if (!super.equals(o)) {
            return false;
        }
        MetaFieldDO entity = (MetaFieldDO) o;
        return getId().equals(entity.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId());
    }
}